<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>管理系统主界面</title>
    <link rel="stylesheet" href="http://localhost:8080/static/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">layout demo</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>

            <li class="layui-nav-item layui-hide-xs"><a href="">待开发1号</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="">待开发2号</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="">待开发3号</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">待开发下拉框</a>
                <dl class="layui-nav-child">
                    <dd><a href="">菜单1.1</a></dd>
                    <dd><a href="">菜单1.2</a></dd>
                    <dd><a href="">菜单1.3</a></dd>
                </dl>
            </li>
        </ul>
        <form action="javascript:void(0);">
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a href="javascript:;">
                    <input type="hidden" name="userId" id="userId" value="">
                    <img class="layui-nav-img" id="img">
                    <input type="text" name="loginName" value="" disabled="disabled" style="width: 50px;">
                </a>
                <dl class="layui-nav-child" id="layui-nav-child-01">
                    <dd data-url="http://localhost:8080/static/user/sys_user_personal.html?userId="><a href="javascript:;">个人主页</a></dd>
                    <dd><a href="">布局设置</a></dd>
                    <dd><a href="http://localhost:8080/system/login.do">退出登录</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-more-vertical"></i>
                </a>
            </li>
        </ul>
        </form>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <dd><a href="">首页</a></dd>
                    <a class="" href="javascript:;">系统管理</a>
                    <dl class="layui-nav-child" id="layui-nav-child-02">
                        <dd data-url="http://localhost:8080/static/user/layui_user_index.html"><a href="javascript:;">用户管理</a></dd>
                        <dd data-url="http://localhost:8080/static/role/layui_role_index.html"><a href="javascript:;">角色管理</a></dd>
                        <dd data-url="http://localhost:8080/static/post/layui_post_index.html"><a href="javascript:;">岗位管理</a></dd>
                        <dd data-url="http://localhost:8080/static/dept/layui_dept_index.html"><a href="javascript:;">部门管理</a></dd>
                        <dd data-url="http://localhost:8080/static/notice/layui_notice_index.html"><a href="javascript:;">通知公告</a></dd>
                        <dd><a href="javascript:;">待开发中...</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">

                    <a href="javascript:;">系统监控</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">数据监控</a></dd>
                        <dd><a href="javascript:;">待开发中...</a></dd>

                    </dl>
                </li>
                <li class="layui-nav-item"><a href="javascript:;">系统工具</a></li>
                <li class="layui-nav-item"><a href="">目录的终点</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">

        <iframe frameborder="0" scrolling="yes" width="100%" height="100%" src="" lang=""></iframe>
    </div>

</div>
<script src="http://localhost:8080/static/layui/layui.js"></script>
<script src="http://localhost:8080/static/layui/js/jquery-3.6.3.js" type="text/javascript"></script>
<script>

    $(function () {
        //获取请求地址栏(url)中带id的参数名称
        let loginUserId = getQueryletiable("userId");
        //console.log("loginUserId:"+loginUserId);

        selectUser(loginUserId);

        //用户主页界面方法
        $("#layui-nav-child-01 dd").on('click',function () {

            //获取登录的id信息
            let userId = $("#userId").val();
            //console.log("userId"+userId);
            let data_url = $(this).attr("data-url");

            //将id信息添加进地址栏
            data_url += userId;
            $("iframe").attr("src",data_url);
            //$("iframe").attr("lang",data_url);
        });

        $("#layui-nav-child-02 dd").on('click',function () {

            let data_url = $(this).attr("data-url");

            $("iframe").attr("src",data_url);
            //$("iframe").attr("lang",data_url);
        });
    });

    //在编辑页面中回显数据
    function getQueryletiable(key) {
        let url = location.search;  //获取当前地址栏请求数据
        let theRequest = new Object();
        if (url.indexOf("?") != -1) {
            let str = url.substr(1);
            let strInfo = str.split("&");
            for (let i = 0; i < strInfo.length; i++) {
                theRequest[strInfo[i].split("=")[0]] = unescape(strInfo[i].split("=")[1]);
            }
        }
        let value = (theRequest[key] == null || theRequest[key] == undefined) ? null : theRequest[key];
        return value;
    }

    //JS
    layui.use(['element', 'layer', 'util'], function () {
        let element = layui.element
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function (othis) {
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            , menuRight: function () {
                layer.open({
                    type: 1
                    , content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                    , area: ['260px', '100%']
                    , offset: 'rt' //右上角
                    , anim: 5
                    , shadeClose: true
                });
            }
        });

    });

    //个人信息显示
    function selectUser(loginUserId) {
        $.ajax({
            url: "http://localhost:8080/sysUser/selectAllUser.do",
            data: {"userId": loginUserId},
            success: function (res) {
                let user = res.data[0];
                let url = 'http://localhost:8080/';
                url += user.avatar;
                $('#img').attr('src', url);

                $("[name= 'userId']").val(user.userId);
                $("[name= 'avatar']").val(user.avatar);
                $("[name= 'loginName']").val(user.loginName);

            },
            error: function () {
                console.log("err...");
            }
        });
    }

</script>
</body>
</html>